<?php
use library\UsualToolInc\UTInc;
use library\UsualToolData\UTData;
$l=$_GET["l"];
$app->Runin(array("l","data"),array($l,UTData::QueryData("cms_pay","","","","1")["querydata"]));
if($_GET["do"]=="update"){
    $id=UTInc::SqlCheck($_POST["id"]);
    $ali_appid=UTInc::SqlCheck($_POST["ali_appid"]);
    $ali_private_key=UTInc::SqlCheck($_POST["ali_private_key"]);
    $ali_public_key=UTInc::SqlCheck($_POST["ali_public_key"]);
    $ali_notify_url=UTInc::SqlCheck($_POST["ali_notify_url"]);
    $ali_return_url=UTInc::SqlCheck($_POST["ali_return_url"]);
    $wx_appid=UTInc::SqlCheck($_POST["wx_appid"]);
    $wx_mchid=UTInc::SqlCheck($_POST["wx_mchid"]);
    $wx_key=UTInc::SqlCheck($_POST["wx_key"]);
    $wx_secert=UTInc::SqlCheck($_POST["wx_secert"]);
    $wx_notify_url=UTInc::SqlCheck($_POST["wx_notify_url"]);
    $pp_mod=UTInc::SqlCheck($_POST["pp_mod"]);
    $pp_clientid=UTInc::SqlCheck($_POST["pp_clientid"]);
    $pp_secret=UTInc::SqlCheck($_POST["pp_secret"]);
    $pp_return_url=UTInc::SqlCheck($_POST["pp_return_url"]);
    $pp_notify_url=UTInc::SqlCheck($_POST["pp_notify_url"]);
    $url_ok=UTInc::SqlCheck($_POST["url_ok"]);
    $url_no=UTInc::SqlCheck($_POST["url_no"]);
    if(!empty($id)){
        if($l=="alipay"):
            $sql=UTData::UpdateData("cms_pay",array(
                "ali_appid"=>$ali_appid,
                "ali_private_key"=>$ali_private_key,
                "ali_public_key"=>$ali_public_key,
                "ali_notify_url"=>$ali_notify_url,
                "ali_return_url"=>$ali_return_url),"id='$id'");
        elseif($l=="wechat"):
            $sql=UTData::UpdateData("cms_pay",array(
                "wx_appid"=>$wx_appid,
                "wx_mchid"=>$wx_mchid,
                "wx_key"=>$wx_key,
                "wx_secert"=>$wx_secert,
                "wx_notify_url"=>$wx_notify_url),"id='$id'");
        elseif($l=="paypal"):
            $sql=UTData::UpdateData("cms_pay",array(
                "pp_mod"=>$pp_mod,
                "pp_clientid"=>$pp_clientid,
                "pp_secret"=>$pp_secret,
                "pp_return_url"=>$pp_return_url,
                "pp_notify_url"=>$pp_notify_url),"id='$id'");
        elseif($l=="url"):
            $sql=UTData::UpdateData("cms_pay",array(
                "url_ok"=>$url_ok,
                "url_no"=>$url_no),"id='$id'");
        endif;
    }else{
        if($l=="alipay"):
            $sql=UTData::InsertData("cms_pay",array(
                "ali_appid"=>$ali_appid,
                "ali_private_key"=>$ali_private_key,
                "ali_public_key"=>$ali_public_key,
                "ali_notify_url"=>$ali_notify_url,
                "ali_return_url"=>$ali_return_url));
        elseif($l=="wechat"):
            $sql=UTData::InsertData("cms_pay",array(
                "wx_appid"=>$wx_appid,
                "wx_mchid"=>$wx_mchid,
                "wx_key"=>$wx_key,
                "wx_secert"=>$wx_secert,
                "wx_notify_url"=>$wx_notify_url));
        elseif($l=="paypal"):
            $sql=UTData::InsertData("cms_pay",array(
                "pp_mod"=>$pp_mod,
                "pp_clientid"=>$pp_clientid,
                "pp_secret"=>$pp_secret,
                "pp_return_url"=>$pp_return_url,
                "pp_notify_url"=>$pp_notify_url));
        elseif($l=="url"):
            $sql=UTData::InsertData("cms_pay",array(
                "url_ok"=>$url_ok,
                "url_no"=>$url_no));                
        endif;
    }
    if($sql):
        UTInc::GoUrl("?m=payment&l=".$l,"操作成功!");
    else:
        UTInc::GoUrl("?m=payment&l=".$l,"操作失败!");
    endif;
}
$app->Open("index.cms");